/*
    SUSAN® - Sole of Unix Save ANything

   
   Copyright (C) 2011-2016 Skyatlas Co. LTD
   

   

   

   
*/
/*
 * Kern Sibbald, October 2007
 */
/** @file
 * SUSAN pluginloader
 */
#if defined(HAVE_MINGW)
#include "include/susan.h"
#include "gtest/gtest.h"
#else
#include "gtest/gtest.h"
#include "include/susan.h"
#endif

#include "dird/dird.h"
#include "dird/dird_globals.h"
#include "dird/dir_plugins.h"
#include "lib/edit.h"

namespace directordaemon {

DirectorResource* me = nullptr;

bool DbGetPoolRecord(JobControlRecord*, SusanDb*, PoolDbRecord*);
bool DbGetPoolRecord(JobControlRecord*, SusanDb*, PoolDbRecord*)
{
  return true;
}

TEST(dir, dir_plugins)
{
  me = new DirectorResource;
  ASSERT_NE(me, nullptr);

  char plugin_dir[PATH_MAX];
  JobControlRecord mjcr1, mjcr2;
  JobControlRecord* jcr1 = &mjcr1;
  JobControlRecord* jcr2 = &mjcr2;

  InitMsg(NULL, NULL);

  OSDependentInit();
  (void)!getcwd(plugin_dir, sizeof(plugin_dir) - 1);

  LoadDirPlugins(plugin_dir, NULL);

  jcr1->JobId = 111;
  NewPlugins(jcr1);

  jcr2->JobId = 222;
  NewPlugins(jcr2);

  EXPECT_EQ(GeneratePluginEvent(jcr1, bDirEventJobStart, (void*)"Start Job 1"),
            bRC_OK);
  EXPECT_EQ(GeneratePluginEvent(jcr1, bDirEventJobEnd), bRC_OK);
  EXPECT_EQ(GeneratePluginEvent(jcr2, bDirEventJobStart, (void*)"Start Job 1"),
            bRC_OK);
  FreePlugins(jcr1);
  EXPECT_EQ(GeneratePluginEvent(jcr2, bDirEventJobEnd), bRC_OK);
  FreePlugins(jcr2);

  UnloadDirPlugins();

  TermMsg();
  CloseMemoryPool();
}

} /* namespace directordaemon */
